package ch.zbw.iCoach.remo;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * The main function of this method is to handle the access to a arrayList.
 * 
 * @author Remo Reimann
 * @version Version 1 (release 18.03.2013)
 */
public class UserList {
	
	//ArrayList for saving / holding user references.
	private ArrayList<User> userListe;

	/**
	 * The constructor of this class just initialized a new ArrayList which can 
	 * save/hold User classes.
	 */
	public UserList() {
		this.userListe = new ArrayList<User>();
	}
	
	/**
	 * This method is used for adding a new user class to the arrayList 
	 * 
	 * @param user	a new User class
	 * @return		boolean value (ture = successful / false = fail)
	 */
	public boolean addUser (User user){
		return this.userListe.add(user);
		
	}
	
	/**
	 * this method is used for deleting a specific user by an specific index
	 * 
	 * @param index	in value which pointed to the user you want delete.
	 */
	public void deleteUser (int index){
		userListe.remove(index);
	}
	
	/**You can select an user by a index.
	 * this method need an index which is used to locate the User
	 * in the arraylist
	 * 
	 * @param index		index of a you you want have a reference
	 * @return			returns you a user reference
	 * @throws 			IndexOutOfBoundsException (happen when the index is invalid)
	 */
	public User getUser(int index)throws IndexOutOfBoundsException{
		
		if (index >= this.getSize() && userListe.isEmpty()){
			throw new IndexOutOfBoundsException("no user in the database.");
		}
		if (index >= this.getSize()){
			throw new IndexOutOfBoundsException("invalid index. Please tray again.");
		}
		int tempindex = index; 
		return this.userListe.get(index);
	}
	
	/**
	 * This method gives you an int value back. The value is the size
	 * of the Array
	 * 
	 * @return			returns you an index value, which shows you the arrayList size.
	 */
	public int getSize(){
		return this.userListe.size();
	}
	
	/**
	 * this method drop the whole userList
	 */
	public void clearAllData()
	{
		userListe.clear();
	}

}
